<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
%>
<form id="form_post_input" class="form-horizontal">
  <input type="hidden" name="keyId" id="keyId" value="${keyId}"/>
  <div id="container_post_input"></div>
</form>

<script id="templates_post_input" type="text/x-jsrender">

  <div class="form-group">
    <label class="col-md-3 control-label">序号</label>
    <div class="col-md-7">
      <input type="number" name="sortNo" id="sortNo" value="{{:sortNo}}" class="form-control" placeholder="请输入序号">
    </div>
  </div>
  <div class="form-group">
    <label class="col-md-3 control-label">岗位名称</label>
    <div class="col-md-7">
      <input type="text" name="name" id="name" value="{{:name}}" class="form-control" placeholder="请输入岗位名称">
    </div>
  </div>
  <div class="form-group">
    <label class="col-md-3 control-label">岗位描述</label>
    <div class="col-md-7">
      <input type="text" name="description" id="description" value="{{:description}}" class="form-control" placeholder="请输入岗位描述">
    </div>
  </div>

</script>

<script>

  $(function(){

    // 加载数据
    fn_post_input_load();

  });

  // 初始化表单数据
  function fn_post_input_load() {
    var $templates = $.templates("#templates_post_input");
    var $container = $("#container_post_input");
    var keyId = $("#keyId").val();

    var url;
    if (keyId) {
      url = "<%=path%>/main/post/read/" + keyId;
    } else {
      url = "<%=path%>/main/post/init";
    }
    __ajax_get(url, null, function(data) {
      if (data.state == 1) {
        var entity = data.data;

        // 初始化模板
        var html = $templates.render(entity);
        $container.html(html);

        // 表单数据校验
        fn_post_input_validate();

      }
    });
  }

  // 表单数据校验
  function fn_post_input_validate() {
    __init_validate('form_post_input', {
      rules : {
        name : {
          required : true
        }
      },
      messages : {
        name : {
          required : "请输入岗位名称"
        }
      }
    });
  }

  function fn_post_input_save(callback) {
    if (!$("#form_post_input").valid()) {
      return false;
    }
    __confirm_dialog(null, '确定提交么?',
            function () {
              __form_save("form_post_input", "<%=path%>/main/post/save", function(data) {
                if(data.state == 1){

                  callback(data.data);
                } else {
                  callback();
                }
              });
            },
            function () {
              callback();
            }
    );
  }

</script>